package com.xzw.cameratest.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.business.entity.PtzPrePointInfo;
import com.xzw.cameratest.R;

import java.util.List;


public class PresetPositionAdapter extends RecyclerView.Adapter<PresetPositionAdapter.PresetPositionViewHolder> {

    private List<PtzPrePointInfo> prePointInfos;
    private Context mContext;
    private OnItemClickListener onItemClickListener;

    public PresetPositionAdapter(Context context, List<PtzPrePointInfo> prePointInfos) {
        this.mContext = context;
        this.prePointInfos = prePointInfos;
    }

    @NonNull
    @Override
    public PresetPositionViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_preset_position, viewGroup, false);
        return new PresetPositionViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull PresetPositionViewHolder presetPositionViewHolder, final int i) {
        presetPositionViewHolder.tv_preset_position_name.setText(prePointInfos.get(i).getName());
        presetPositionViewHolder.tv_preset_position_name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListener.onItemClick(v, prePointInfos.get(i));
            }
        });
    }

    @Override
    public int getItemCount() {
        return prePointInfos == null ? 0 : prePointInfos.size();
    }

    static class PresetPositionViewHolder extends RecyclerView.ViewHolder {
        TextView tv_preset_position_name;

        PresetPositionViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_preset_position_name = itemView.findViewById(R.id.tv_preset_position_name);
        }
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    public interface OnItemClickListener {
        void onItemClick(View v, PtzPrePointInfo info);
    }
}
